package com.base.config;

import com.base.config.Interceptor.Intercept;
import com.base.config.Interceptor.OtherIntercept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 开发公司：个人
 * 版权：刘志强
 * <p>
 * WebMvcConfig
 *
 * @author 刘志强
 * @created Create Time: 2019/2/16
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Autowired
    public Intercept intercept;
    @Autowired
    public OtherIntercept otherIntercept;
    //添加资源处理程序，resources资源目录下的static目录下的资源可以被直接访问
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 多个拦截器组成一个拦截器链
         * addPathPatterns 用于添加拦截规则
         * excludePathPatterns 用于排除拦截
         */
        registry.addInterceptor(intercept)
                .addPathPatterns("/**")
                .excludePathPatterns("/index");

        registry.addInterceptor(otherIntercept)
                .addPathPatterns("/**");

        super.addInterceptors(registry);
    }
}
